<template>
    <div>

        <el-row :gutter="20">
            <!--部门数据-->
            <el-col :span="4" :xs="24">
                <div class="head-container">
                    <el-input
                            v-model="deptName"
                            placeholder="请输入部门名称"
                            clearable
                            size="small"
                            prefix-icon="el-icon-search"
                            style="margin-bottom: 20px"
                    />
                </div>
                <div class="head-container">
                    <el-tree
                            :data="deptOptions"
                            :props="defaultProps"
                            :expand-on-click-node="false"
                            ref="tree"
                            node-key="id"
                            default-expand-all
                            highlight-current
                            @node-click="handleNodeClick"
                    />
                </div>
            </el-col>
            <!--用户数据-->
            <el-col :span="20" :xs="24">
                <el-form  :model="queryParams" ref="queryForm" size="small" :inline="true"
                         label-width="68px">
                    <el-form-item label="用户名称" prop="userName">
                        <el-input
                                v-model="queryParams.userName"
                                placeholder="请输入用户名称"
                                clearable
                                style="width: 240px"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
                    <el-form-item label="手机号码" prop="phonenumber">
                        <el-input
                                v-model="queryParams.phonenumber"
                                placeholder="请输入手机号码"
                                clearable
                                style="width: 240px"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>

                    <el-form-item label="创建时间">
                        <el-date-picker
                                v-model="dateRange"
                                style="width: 240px"
                                value-format="yyyy-MM-dd"
                                type="daterange"
                                range-separator="-"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
                <el-table v-loading="loading" :data="userList" >
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="用户编号" align="center" key="userId" prop="userId"  />
                    <el-table-column label="用户名称" align="center" key="userName" prop="userName"  :show-overflow-tooltip="true" />
                    <el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" />
                    <el-table-column label="部门" align="center" key="deptName" prop="dept.deptName"  :show-overflow-tooltip="true" />
                    <el-table-column label="手机号码" align="center" key="phonenumber" prop="phonenumber"  width="120" />
                    <el-table-column label="状态" align="center" key="status" >
<!--                        <template slot-scope="scope">-->
<!--                            <el-switch-->
<!--                                    v-model="scope.row.status"-->
<!--                                    active-value="0"-->
<!--                                    inactive-value="1"-->
<!--                                    @change="handleStatusChange(scope.row)"-->
<!--                            ></el-switch>-->
<!--                        </template>-->
                    </el-table-column>
                    <el-table-column label="创建时间" align="center" prop="createTime"  width="160">
<!--                        <template slot-scope="scope">-->
<!--                            <span>{{ parseTime(scope.row.createTime) }}</span>-->
<!--                        </template>-->
                    </el-table-column>
                    <el-table-column
                            label="操作"
                            align="center"
                            width="160"
                            class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope" v-if="scope.row.userId !== 1">
                            <el-button
                                    size="mini"
                                    type="text"
                                    icon="el-icon-edit"
                                    v-hasPermi="['system:user:edit']"
                            >修改</el-button>
                            <el-button
                                    size="mini"
                                    type="text"
                                    icon="el-icon-delete"
                            >删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div  v-hasPermi="['system:user:edit']" >111</div>
<!--                <div v-has-permi="['1:2:3']" >111</div>-->
            </el-col>
        </el-row>
    </div>
</template>
<script>
    // @ is an alias to /src
    import {
        listUser,
        getUser,
        delUser,
        addUser,
        updateUser,
        resetUserPwd,
        changeUserStatus,
        deptTreeSelect
    } from "@/api/user";
    import {getToken} from "@/utils/auth";

    export default {
        // name: 'user',
        data() {
            return {
                // 遮罩层
                loading: true,
                total: 0,
                // 用户表格数据
                userList: null,
                deptName: '',
                defaultProps: {
                    children: "children",
                    label: "label"
                },
                deptOptions: undefined,
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    userName: undefined,
                    phonenumber: undefined,
                    status: undefined,
                    deptId: undefined
                },
                dateRange:[],
            };
        },
        components: {},
        created() {
            this.getList();
        },
        methods: {
            /** 查询用户列表 */
            getList() {
                this.loading = true;
                listUser().then(response => {
                        this.userList = response.rows;
                        this.total = response.total;
                        this.loading = false;
                        console.log(response)
                    }
                );
            },
            // 节点单击事件
            handleNodeClick(data) {
                // this.queryParams.deptId = data.id;
                // this.handleQuery();
                console.log(data)
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                // this.dateRange = [];
                // this.resetForm("queryForm");
                // this.queryParams.deptId = undefined;
                // this.$refs.tree.setCurrentKey(null);
                // this.handleQuery();
            },
        }
    }
</script>